/*
    This file is part of open-wars <http://code.google.com/p/open-wars/>.

    open-wars is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    open-wars is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with open-wars.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef opengl_renderer_h
#define opengl_renderer_h

#ifdef WIN32
	#include <Windows.h>
	#include <gl/gl.h>
	#include <gl/glu.h>
	#include <freeglut.h>
#elif IS_OSX
	#include <OpenGL/gl.h>
	#include <OpenGL/glu.h>
	#include <GLUT/glut.h>	
#else
	#include <GL/gl.h>
	#include <GL/freeglut.h>
#endif

#include <list>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/foreach.hpp>

#include <png.h>
#include <opengl-font.h>

#include <renderer-interface.h>

class OpenGLRenderer : public IRendererInterface
{

	// IRendererInterface ==========================================================================
	public:
	
		virtual void InitializeWindow                       (NUMBER width, NUMBER height, NUMBER depth);
		virtual void DestroyWindow                          (void);
		virtual void SetWindowResolution                    (NUMBER width, NUMBER height, NUMBER depth);
		virtual IRendererResResult GetWindowResolution      (void);
		virtual void SetFullScreen                          (BOOLEAN fullScreen);
		virtual void SetWindowCaption						(STRING caption);
		virtual TEXTURE LoadTextureFromFile                 (STRING fileName);
		virtual void DrawTexture							(TEXTURE texture, float x, float y, int width, int height);
		virtual void DrawLine								(float x1, float y1, float x2, float y2, float w, int r, int g, int b, int a);
		virtual void DrawRect								(float x, float y, float w, float h, int r, int g, int b, int a);
		virtual DISPLAYLIST DisplayCreateList				(void);
		virtual void DisplayBeginList						(DISPLAYLIST displayList);
		virtual void DisplayEndList							(void);
		virtual void DisplayDrawList						(DISPLAYLIST displayList);
		virtual void DisplayTranslate						(float x, float y);
		virtual void DisplayPushMatrix						(void);
		virtual void DisplayPopMatrix						(void);
		virtual FONT LoadFont								(STRING fileName, int point);
		virtual void DrawFont								(FONT font, float x, float y, int r, int g, int b, int a, STRING t);
		virtual void FreeFont								(FONT font);
        virtual void Repaint                                (void);
	// =============================================================================================
	
	public:
		OpenGLRenderer(int argc, char** argv);
		~OpenGLRenderer();
		void renderScene(void);
	
	private:
		BOOLEAN isFullScreen;
		int glutWindowID;
		IRendererResResult resolutionInfo;
		int GetTextureInfo(int ColourType);
		

        void onPaint(void);
        void onIdlePaint(void);
};

#endif // opengl_renderer_h
